package com.boot.dao;

import com.boot.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import java.util.Collection;
import java.util.List;

@Repository
public class UserDao {

    @Autowired
    JdbcTemplate jdbcTemplate;

    public List<User> getUser(User user) {
        String sql = "select id,addTime,userName,password from t_user where userName=? and password=?";
        return jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(User.class), user.getUserName(),user.getPassword());
    }

    public Boolean save(User user) {
        String sql = "insert into t_user(userName,password) values(?,?)";
        return jdbcTemplate.update(sql, user.getUserName(),user.getPassword()) == 1;
    }
}
